﻿#include "dialogselectheader.h"
#include "qboxlayout.h"
#include "ui_dialogselectheader.h"

#include <QCheckBox>

DialogSelectHeader::DialogSelectHeader(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogSelectHeader)
{
    ui->setupUi(this);
}

DialogSelectHeader::~DialogSelectHeader()
{
    delete ui;
}

void DialogSelectHeader::SetListHeader(const QList<QString> &headers)
{
    ListHeader = headers;
    ShowHeaderCheck();
}

void DialogSelectHeader::ShowHeaderCheck()
{
    QGridLayout *layout = new QGridLayout();
    for(int i=0;i<ListHeader.count();i++)
    {
        QCheckBox* checkbox = new QCheckBox(ListHeader[i]);
        checkbox->setChecked(true);
        layout->addWidget(checkbox);
    }
     ui->groupBox->setLayout(layout);
}

QList<QString> DialogSelectHeader::GetSelectHeaders()
{
    QList<QString> listHeaderSelect;
    auto controls=ui->groupBox->children();
    for (int var = 0; var < controls.size(); ++var) {

        QCheckBox* checkbox=qobject_cast<QCheckBox*>(controls[var]);
        if(checkbox!=nullptr)
        {
            if(checkbox->isChecked())
                listHeaderSelect.append(checkbox->text());
        }
    }

    return listHeaderSelect;
}

void DialogSelectHeader::on_buttonBox_accepted()
{
    ListHeaderSelect=GetSelectHeaders();
}

